package com.ruoyi.subject.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.subject.mapper.SubjectFundsMapper;
import com.ruoyi.subject.domain.SubjectFunds;
import com.ruoyi.subject.service.ISubjectFundsService;

/**
 * 课题经费Service业务层处理
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Service
public class SubjectFundsServiceImpl implements ISubjectFundsService 
{
    @Autowired
    private SubjectFundsMapper subjectFundsMapper;

    /**
     * 查询课题经费
     * 
     * @param id 课题经费ID
     * @return 课题经费
     */
    @Override
    public SubjectFunds selectSubjectFundsById(Long id)
    {
        return subjectFundsMapper.selectSubjectFundsById(id);
    }

    /**
     * 查询课题经费列表
     * 
     * @param subjectFunds 课题经费
     * @return 课题经费
     */
    @Override
    public List<SubjectFunds> selectSubjectFundsList(SubjectFunds subjectFunds)
    {
        return subjectFundsMapper.selectSubjectFundsList(subjectFunds);
    }

    /**
     * 新增课题经费
     * 
     * @param subjectFunds 课题经费
     * @return 结果
     */
    @Override
    public int insertSubjectFunds(SubjectFunds subjectFunds)
    {
        subjectFunds.setCreateTime(DateUtils.getNowDate());
        subjectFunds.setCreateBy(SecurityUtils.getUsername());
        return subjectFundsMapper.insertSubjectFunds(subjectFunds);
    }

    /**
     * 修改课题经费
     * 
     * @param subjectFunds 课题经费
     * @return 结果
     */
    @Override
    public int updateSubjectFunds(SubjectFunds subjectFunds)
    {
    	if(!"0".equals(subjectFunds.getCheckStatus())) {
    		subjectFunds.setCheckTime(DateUtils.getNowDate());
    		subjectFunds.setCheckUserId(SecurityUtils.getLoginUser().getUser().getUserId());
    	}
        subjectFunds.setUpdateTime(DateUtils.getNowDate());
        subjectFunds.setUpdateBy(SecurityUtils.getUsername());
        return subjectFundsMapper.updateSubjectFunds(subjectFunds);
    }

    /**
     * 批量删除课题经费
     * 
     * @param ids 需要删除的课题经费ID
     * @return 结果
     */
    @Override
    public int deleteSubjectFundsByIds(Long[] ids)
    {
        return subjectFundsMapper.deleteSubjectFundsByIds(ids);
    }

    /**
     * 删除课题经费信息
     * 
     * @param id 课题经费ID
     * @return 结果
     */
    @Override
    public int deleteSubjectFundsById(Long id)
    {
        return subjectFundsMapper.deleteSubjectFundsById(id);
    }
}
